1. Field of the Invention
This invention is related to the field of processors and, more particularly, to branch prediction mechanisms in processors.
2. Description of the Related Art
A critical aspect of the performance of a processor is its ability to handle conditional branches. Conditional branches cause instruction fetching to shift from the sequential path to a target path if a condition specified by the branch is true, and do not cause the shift if the specified condition is false. Accordingly, when fetched instructions include a conditional branch, subsequent fetching is dependent on resolving the condition specified by the conditional branch. Simply stalling subsequent fetching is one option, but that option often leads to lower performance. Accordingly, many processors implement some form of branch prediction.
One popular form of branch prediction involves training branch predictions stored in a branch prediction array based on the past execution behavior of conditional branches. Indexing the branch prediction array to select a branch prediction is dependent on the fetch address that corresponds to a given conditional branch. Additionally, in some mechanisms, a branch history is maintained that is used in the index generation. Since the behavior of a given branch may depend on the route of instruction execution that arrived at the given branch, including the branch history in the index generation may cause different branch predictions to be used (and trained) for different branch histories.
Accordingly, maintaining a consistent branch history for each fetch request is an important part of ensuring branch prediction accuracy. In a pipelined processor, where the update of the branch history may be delayed one or more clock cycles from its use in index generation, the consistency of the branch history is difficult to maintain. For example, if one fetch request passes through the pipeline and another, subsequent fetch request is close behind, the branch history that exists for the subsequent fetch request may not yet have been updated to reflect the previous fetch request. On the other hand, if the subsequent fetch request is delayed with respect to the previous fetch request, the branch history for the subsequent fetch request will be updated to reflect the previous fetch request. Accordingly, inconsistent branch histories may be used for the same fetch request, depending on its timing with respect to previous fetch requests. Branch prediction accuracy may be negatively impacted, which may impact overall performance.